//
//  UIButton+YSJBTN.m
//  99Customer
//
//  Created by Luolc on 2017/12/22.
//  Copyright © 2017年 Luolc. All rights reserved.
//

#import "UIButton+YSJBTN.h"

@implementation UIButton (YSJBTN)

+(UIButton *)createHomeBtnWithFrame:(CGRect)frame andTitle:(NSString *)title andIcon:(NSString *)icon {
    
    UIButton *retBtn = [[UIButton alloc] initWithFrame:frame];
    
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, retBtn.width, retBtn.height-20-10)];
    imageView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    imageView.image = [UIImage imageNamed:icon];
    [retBtn addSubview:imageView];
    imageView.layer.cornerRadius = imageView.width/2.0;
    imageView.layer.masksToBounds = YES;
    
    UILabel *label = [[UILabel alloc] init];
    label.text = title;
    label.font = [UIFont systemFontOfSize:12];
    label.textColor = [UIColor blackColor];
    label.frame = CGRectMake(0, imageView.bottom+6, imageView.width, 18);
    label.textAlignment = NSTextAlignmentCenter;
    [retBtn addSubview:label];
    
    return retBtn;
}


+ (void)updateBtnStyle_rightImage:(UIButton *)btn {
    
    CGFloat btnImageWidth = btn.imageView.bounds.size.width;
    CGFloat btnLabelWidth = btn.titleLabel.bounds.size.width;
    CGFloat margin = 3;
    
    btnImageWidth += margin;
    btnLabelWidth += margin;
    
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btnImageWidth, 0, btnImageWidth)];
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btnLabelWidth, 0, -btnLabelWidth)];
}

+ (void)updateBtnStyle_rightImage:(UIButton *)btn andMargin:(CGFloat)margin {
    
    CGFloat btnImageWidth = btn.imageView.bounds.size.width;
    CGFloat btnLabelWidth = btn.titleLabel.bounds.size.width;
    
    CGFloat margin2 = margin;
    
    btnImageWidth += margin2;
    btnLabelWidth += margin2;
    
    [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btnImageWidth, 0, btnImageWidth)];
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btnLabelWidth, 0, -btnLabelWidth)];
}

@end
